package com.yc.cloud.admin.dto.mediakit;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "MediaKitOnPublishResponse", description = "MediaKit on_publish 推流事件响应")
public class MediaKitOnPublishResponse {

    @ApiModelProperty("错误代码，0代表允许推流")
    private Integer code = 0;

    @ApiModelProperty("是否添加静音音频")
    @JsonProperty("add_mute_audio")
    private Boolean addMuteAudio = true;

    @ApiModelProperty("断开推流后，延迟多少毫秒关闭流")
    @JsonProperty("continue_push_ms")
    private Integer continuePushMs = 10000;

    @ApiModelProperty("是否开启音频")
    @JsonProperty("enable_audio")
    private Boolean enableAudio = true;

    @ApiModelProperty("是否开启fmp4")
    @JsonProperty("enable_fmp4")
    private Boolean enableFmp4 = true;

    @ApiModelProperty("是否开启hls")
    @JsonProperty("enable_hls")
    private Boolean enableHls = true;

    @ApiModelProperty("是否开启hls fmp4")
    @JsonProperty("enable_hls_fmp4")
    private Boolean enableHlsFmp4 = false;

    @ApiModelProperty("是否开启mp4")
    @JsonProperty("enable_mp4")
    private Boolean enableMp4 = false;

    @ApiModelProperty("是否开启rtmp")
    @JsonProperty("enable_rtmp")
    private Boolean enableRtmp = true;

    @ApiModelProperty("是否开启rtsp")
    @JsonProperty("enable_rtsp")
    private Boolean enableRtsp = true;

    @ApiModelProperty("是否开启ts")
    @JsonProperty("enable_ts")
    private Boolean enableTs = true;

    @ApiModelProperty("hls保存路径")
    @JsonProperty("hls_save_path")
    private String hlsSavePath = "/hls_save_path/";

    @ApiModelProperty("是否修改时间戳")
    @JsonProperty("modify_stamp")
    private Boolean modifyStamp = false;

    @ApiModelProperty("mp4录制时是否当作播放器")
    @JsonProperty("mp4_as_player")
    private Boolean mp4AsPlayer = false;

    @ApiModelProperty("mp4录制切片时间，单位秒")
    @JsonProperty("mp4_max_second")
    private Integer mp4MaxSecond = 3600;

    @ApiModelProperty("mp4保存路径")
    @JsonProperty("mp4_save_path")
    private String mp4SavePath = "/mp4_save_path/";

    @ApiModelProperty("是否自动关闭流")
    @JsonProperty("auto_close")
    private Boolean autoClose = false;

     @ApiModelProperty("流替换")
     @JsonProperty("stream_replace")
     private String streamReplace = "";

    /**
     * 创建允许推流的响应
     */
    public static MediaKitOnPublishResponse allow() {
        MediaKitOnPublishResponse response = new MediaKitOnPublishResponse();
        response.setCode(0);
        return response;
    }

    /**
     * 创建拒绝推流的响应
     */
    public static MediaKitOnPublishResponse deny(String reason) {
        MediaKitOnPublishResponse response = new MediaKitOnPublishResponse();
        response.setCode(-1);
        // 可以通过stream_replace字段返回错误信息
        response.setStreamReplace(reason);
        return response;
    }

    /**
     * 创建自定义配置的允许推流响应
     */
    public static MediaKitOnPublishResponse allowWithConfig(boolean enableRecording) {
        MediaKitOnPublishResponse response = new MediaKitOnPublishResponse();
        response.setCode(0);
        
        // 如果需要录制，启用mp4
        if (enableRecording) {
            response.setEnableMp4(true);
            response.setMp4SavePath("/opt/media/bin/www/record/");
        }
        
        return response;
    }
}
